package com.neusoft.neuiotms.dcom.controller.incident;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.bizcore.auth.common.bean.UserBean;
import com.neusoft.bizcore.web.dto.result.ResultDTO;
import com.neusoft.neuiotms.dcom.dto.incident.IncidentCloseDTO;
import com.neusoft.neuiotms.dcom.service.incident.IncidentCloseService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @author WYS
 * @date 2020年8月18日 下午2:03:59
 */
@Api(tags = "事件关闭")
@RestController
@RequestMapping(value = "/api/w/incident/close")
public class IncidentCloseController {
    @Autowired
    private IncidentCloseService incidentCloseService;

    @ApiOperation("新增事件关闭")
    @PostMapping
    public ResultDTO<IncidentCloseDTO> create(@RequestBody final IncidentCloseDTO dto, final UserBean user) {
        if (user != null) {
            dto.setExecuteUserCode(StringUtils.isEmpty(user.getUsername()) ? "admin" : user.getUsername());
            dto.setExecuteUserName(StringUtils.isEmpty(user.getName()) ? "admin" : user.getName());
        }
        return ResultDTO.success(this.incidentCloseService.create(dto, user));
    }

    @ApiOperation("查看事件关闭")
    @GetMapping("/{workOrderNum}/{taskId}")
    public ResultDTO<IncidentCloseDTO> details(@PathVariable final String workOrderNum,
            @PathVariable final String taskId,
            final UserBean user) {
        return ResultDTO.success(this.incidentCloseService.detail(workOrderNum, taskId, user));
    }

}
